import java.sql.*;

public class Example01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 第一步:加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 第二步:建立连接，"root"和"123123"是针对MySQL设置了用户名(root)和密码(123123
        // 127.0.0.1:3306是mysql服务器地址及端口  数据库编码格式设置为utf-8
        // String url = "jdbc:mysql://localhost:3306";
        String  url = "jdbc:mysql://localhost:3306/rj2306";
        String user = "root";
        String password = "123456";
        Connection conn = DriverManager.getConnection(url, user, password);
        // 第三步:建立statement对象
        Statement statement = conn.createStatement();
        String sql = "select * from staff";
        ResultSet resultSet = statement.executeQuery(sql);
        // 第四步:修改数据
        System.out.println("name\tsex\tphone_number\tmoney\tentry_date");
        while (resultSet.next()) {
            String name = resultSet.getNString("name");
            String sex = resultSet.getNString("sex");
            String phoneNumber = resultSet.getString("phone_number");
            float money = resultSet.getFloat("money");
            Date entryDaten= resultSet.getDate("entry_date");
            System.out.println(name + "\t" + sex + "\t" + phoneNumber + "\t" + money + "\t" + entryDaten);
        }
        // 第五步:关闭statement对象和连接对象
        statement.close();
        conn.close();
    }
}
